/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package org.amit.collections;

import java.io.Serializable;
import java.util.LinkedHashMap;
import java.util.Map;

/**
 *
 * @author amit
 */
public class SimpleLRUCache<K, T> extends LinkedHashMap<K, T> implements Serializable{

    int maxSize;

    public SimpleLRUCache(int maxSize) {
        super();
        this.maxSize = maxSize;
    }

    @Override
    public synchronized T get(Object key) {
        return super.get(key);
    }

    @Override
    public synchronized void putAll(Map<? extends K, ? extends T> m) {
        super.putAll(m);
    }

    @Override
    public synchronized T put(K key, T value) {
        return super.put(key, value);
    }

    @Override
    protected boolean removeEldestEntry(Map.Entry eldest) {
        return size() > maxSize;
    }
}
